# -*- coding: utf-8 -*-
#
# @创建作者: ZQQ
# @创建时间: 2025/7/22 08:22
# @说明:
#
from flask import Flask, request, jsonify

app = Flask(__name__)


@app.route('/received/', methods=['POST'])
def receive_data():
    """接收JSON格式数据的接口"""

    try:
        # 获取JSON请求体
        data = request.json
        print(data)

        if not data:
            return jsonify({"error": "Empty request body"}), 400

        # 此处添加您的数据处理逻辑(示例打印)
        print(f"Received data: {data}")

        # 返回成功响应
        return jsonify({
            "status": "success",
            "message": "Data received",
            "received_data": data
        }), 200

    except Exception as e:
        return jsonify({"error": str(e)}), 500


if __name__ == '__main__':
    # 生产环境建议使用WSGI服务器部署
    app.run(host='0.0.0.0', port=6010, debug=True)
